import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { configoptionlist } from '/@/api/sys/gateway/gateway';
type Props = Partial<DynamicProps<BasicTableProps>>;
import moment from 'moment';
// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '项目',
    dataIndex: 'category',
    fixed: 'left',
    width: 60,
  },
  {
    title: '代码',
    dataIndex: 'name',
    fixed: 'left',
    width: 130,
  },
  {
    title: '参数值',
    dataIndex: 'value',
    width: 100,
  },
  {
    title: '默认值',
    dataIndex: 'default_value',
    width: 100,
  },
  {
    title: '中文描述',
    dataIndex: 'comment',
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'create_time',
    width: 160,
    format: (text) => {
      return moment(parseInt(text) * 1000).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '修改时间',
    dataIndex: 'update_time',
    width: 160,
    format: (text) => {
      return moment(parseInt(text) * 1000).format('YYYY-MM-DD HH:mm:ss');
    },
  },
];

export const formConfig: Partial<FormProps> = {
  labelWidth: 100,
  schemas: searchSchemas,
  actionColOptions: {
    span: 8,
    style: { textAlign: 'left', marginLeft: '40px' },
  },
};

export const tableConfig: Props = {
  api: configoptionlist,
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  clickToRowSelect: false,
  showTableSetting: true,
  tableSetting: { fullScreen: true },
  showIndexColumn: false,
  rowKey: 'id',
  bordered: true,
  fetchSetting: {
    listField: 'list',
    totalField: 'total',
    sizeField: 'page_size',
  },
  actionColumn: {
    width: 60,
    title: '操作',
    slots: { customRender: 'action' },
  },
};
